package com.xwm93up.basic.enumtips;

import java.util.EnumMap;
import java.util.List;

/**
 * @Description: desc
 * @Author: xwm93up
 * @Since: 2021/11/30 15:43
 */
public class EnumMapTest {
    EnumMap<UserRole, Integer> userStatisticsMap = new EnumMap<UserRole, Integer>(UserRole.class);

    // 统计
    private void statistics(List<User> users) {
        for (User user : users) {
            Integer num = userStatisticsMap.get(user.getUserRole());
            if (null != num) {
                userStatisticsMap.put(user.getUserRole(), num + 1);
            } else {
                userStatisticsMap.put(user.getUserRole(), 1);
            }
        }
    }

    /*public static void main(String[] args) {
        List<User> list = new ArrayList<>();
        User user1 = new User();
        user1.setUserRole(UserRole.ROLE_ROOT_ADMIN);
        User user2 = new User();
        user2.setUserRole(UserRole.ROLE_ORDER_ADMIN);
        User user3 = new User();
        user3.setUserRole(UserRole.ROLE_ORDER_ADMIN);
        list.add(user1);
        list.add(user2);
        list.add(user3);
        statistics(list);
        System.out.println(userStatisticsMap);
    }*/
}
